/**
 * 
 */
package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

import model.Novel;
import util.DBHelper;

/**
 * @author Administrator
 *
 */
public class NovelDao {
	public void addNovel(List<Novel> nlist) throws Exception{
		Connection conn = DBHelper.getConnection();
		String sql = "insert into novel(novelname,url) values(?,?)";
		PreparedStatement ptst = conn.prepareStatement(sql);
		//首先把Auto commit设置为false,不让它自动提交  
		conn.setAutoCommit(false);
		
		for (Novel novel : nlist) {
			ptst.setString(1, novel.getNovelName());
			ptst.setString(2, novel.getNovelURL());
			//将一组参数添加到此 PreparedStatement 对象的批处理命令中。
			ptst.addBatch();
		}
		//将一批参数提交给数据库来执行，如果全部命令执行成功，则返回更新计数组成的数组。
		ptst.executeBatch();
		//进行手动提交（commit） 
		conn.commit();
		//提交完成后回复现场将Auto commit,还原为true
		conn.setAutoCommit(true);
	}
}
